package com.app.business.service;

import com.app.business.model.CarLotBuyPerson;
import com.app.business.model.HouseBuyPerson;
import com.app.system.jpa.JpaBaseDao;
import com.app.system.utils.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ddz on 2019/2/27.
 */
@Service
@SuppressWarnings("all")
public class CarLotBuyPersonService extends JpaBaseDao<CarLotBuyPerson, Integer> {

    /**
     * 通过车位id得到CarLotBuyPerson中的产权人id
     * @param carLotId
     * @return
     */
    @Transactional
    public List<String> getBuyHousePersonIdListByCarLotId(Integer carLotId) {
        String sql = "select buy_house_person_id from car_lot_buy_person  where car_lot_id =:carLotId";
        return this.entityManager.createNativeQuery(sql).setParameter("carLotId", carLotId).getResultList();
    }

    @Transactional
    public List<Integer> getBuyHousePersonIdListByCarLotIdForInteger(Integer carLotId) {
        String sql = "select buy_house_person_id from car_lot_buy_person  where car_lot_id =:carLotId";
        return this.entityManager.createNativeQuery(sql).setParameter("carLotId", carLotId).getResultList();
    }


    /**
     * 通过carlotId删除车位关联的产权人
     * @param carLotId
     */
    @Transactional
    public synchronized void deleteCarLotBuyPersonByCarLotId(Integer carLotId) {
        //查询语句
        String sql = "delete from car_lot_buy_person  where car_lot_id =:carLotId";
        this.entityManager.createNativeQuery(sql).setParameter("carLotId",carLotId).executeUpdate();
    }
    /**
     * 通过buyHousePersonId删除车位关联的产权人
     * @param carLotId
     */
    @Transactional
    public synchronized void deleteCarLotBuyPersonByBuyHousePersonId(Integer buyHousePersonId) {
        //查询语句
        String sql = "delete from car_lot_buy_person  where buy_house_person_id =:buyHousePersonId";
        this.entityManager.createNativeQuery(sql).setParameter("buyHousePersonId",buyHousePersonId).executeUpdate();
    }
}
